package com.sushuo.api.util;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import com.sushuo.base.bean.Product;

@Component
public class RedisTest {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

//    @Autowired
//    private RedisTemplate<String, Product> redisTemplate;
    
    static final String keyString = "yeyiRedisTestTime";

    public String setGetString(){
        // 保存字符串
        String time = new Date().toString();
        stringRedisTemplate.opsForValue().set(keyString, time);
        String t = stringRedisTemplate.opsForValue().get(keyString);
        System.out.println(t);
        return t;
    }

    static final String keyObject = "redisTestKeyYeyi";
    
    public Product setGetProduct(Product product) throws Exception {
        // 保存对象
//        redisTemplate.opsForValue().set(keyObject, product);
//        return redisTemplate.opsForValue().get(key);
        return product;
    } 
}
